<!-- 考核兑现完成 -->
<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <list-table ref="table" size="default" rowKey="id" :columns="columns" :request="loadData" :alert="true"
                :export-config="{
                    use: true,
                    select: '考核兑现完成',
                    all: '考核兑现完成'
                }" :statistics-config="{ use: true, total, temp }" show-size-changer show-quick-jumper
                        :exportPermission="{ select: 'bm_045_exp_03', all: 'bm_045_exp_03' }"
                showPagination="auto">
                <!-- :exportPermission="{select: 'bm_012_edi_02',all: 'bm_012_edi_02'}" -->
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                        <a @click="handleUpdate('looks', record)" v-btnPermission="'bm_045_loo_02'">查看</a>
                        <a @click="handleUpdate('edit', record)"
                            v-if="(record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED') && hideBuquBtn()"
                            v-btnPermission="'bm_045_edi_01'">编辑</a>
                        <a @click="handleApproveDetail(record)" v-if="record.auditStatus !== 'DRAFT'"
                            v-btn-permission="'bm_045_loo_02'">审批信息</a>
                    </MoreButton>
                </span>
            </list-table>
            <ApprovalDetails :title="'审批详情'" :business-id="businessId" :visible="visibleApprove"
                @cancel="visibleApprove = false" @confirm="visibleApprove = false" />
            <!-- 编辑弹窗 -->
            <a-modal title="效益审计资料上报" :visible="visible" width="800px" :confirm-loading="confirmLoading" @ok="handleOk"
                @cancel="handleCancel">
                <a-form-model ref="ruleForm" :model="form" :rules="rules" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }">
                    <a-row :gutter="24">
                        <a-col :md="18" :sm="18">
                            <a-form-model-item label="上报时间" prop="fulfillDate">
                                <a-date-picker v-model="form.fulfillDate" :disabled="disabled"
                                    @change="(date, dateString) => getTime(date, dateString, 'form', 'fulfillDate')" />
                            </a-form-model-item>
                        </a-col>
                        <a-col :md="18" :sm="18">
                            <a-form-model-item label="附件上传">
                                <upload-list :businessCode="'BM19'" :uploadArrys.sync="form.files"
                                    @fileArrysData="handleFileUploaded" multiple :disabled="disabled"></upload-list>
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-form-model>
            </a-modal>
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/list_status'
import ApprovalDetails from '@/components/approvalDetails'
// import { getMeetingList, startMeeting, getSearchList } from '@/api/office/conference'
import { getDischargeList, getDischargeCount, getDischargeOne, saveDischargeList } from '@/api/businessAffairs/assessmentFulfillment'
import { typeListApproval1 } from '@/utils/util'
import UploadList from '@/components/UploadList'
import moment from 'moment'
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },

    {
        title: '分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '项目名称',
        dataIndex: 'projectName',
    },
    {
        title: '考核兑现时间',
        dataIndex: 'fulfillDate',
    },
    {
        title: '填报人',
        dataIndex: 'informant',
    },
    {
        title: '填报时间',
        dataIndex: 'informantDate',
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName'
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
    {
        name: '所属单位',
        valueKey: 'searchQuery',
        type: OrgTreeSelect,
    },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    // {
    //     name: '会议名称',
    //     value: 'meetingName',
    //     type: 'input',
    // },
    {
        name: '考核兑现时间',
        value: 'finishedDate',
        type: 'dateRange',
    },
    {
        name: '填报人',
        value: 'informant',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'informantTime',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval1,
    }
]

export default {
    name: 'ab' + Date.now(),
    components: {
        STable,
        listStatus,
        ApprovalDetails,
        UploadList,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            form: {
                fulfillDate: ''
            },
            rules: {
                fulfillDate: [{ required: true, message: '请选择', change: true }]
            },
            disabled: false,
            visible: false,
            confirmLoading: false,
            total: {},
            countList: {},
            visibleApprove: false,
            //获取流程配置值
            processConfig: null,
            //点击提交发送流程配置值
            setProcessConfig: null,
            businessId: null,
            temp: () => {
                return (
                    <span style="margin-right: 12px">
                        待提交：<span class="totalNum">{this.countList.totalWaitCommitCount}  </span>
                        审批中：<span class="totalNum">{this.countList.totalAuditingCount}  </span>
                        审批通过：<span class="totalNum">{this.countList.totalPassCount}  </span>
                        审批不通过：<span class="totalNum">{this.countList.totalRejectedCount}  </span>
                    </span>
                )
            },
            queryParam: {},
            loadData: async (parameter) => {
                this.queryParam = { ...this.queryParam }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getDischargeCount(requestParameters)
                const res = await getDischargeList(requestParameters)
                res.data.forEach(item => {
                    if (item.auditStatus == 'PAST') {
                        item.auditStatusName = '审批通过'
                    } else if (item.auditStatus == 'SUBMITTED') {
                        item.auditStatusName = '审批中'
                    } else if (item.auditStatus == 'REJECTED') {
                        item.auditStatusName = '审批不通过'
                    } else if (item.auditStatus == 'DRAFT') {
                        item.auditStatusName = '待提交审批'
                    }
                    if(!item.informant) {
                        item.informantDate = ''
                    }
                });
                // console.log(res.data,222)
                return new Promise((resolve, reject) => {
                    resolve(res)
                })
            },

        }
    },
    mounted() {
        // this.getSearchListReq()
    },
    created() {

    },
    methods: {
        getTime(date, dateString, type, name) {
            this[type][name] = dateString
            // console.log(this[type][name])
        },
        handleApproveDetail(record) {
            this.visibleApprove = true
            this.businessId = record.id
        },
        getDischargeCount(requestParameters) {
            getDischargeCount(requestParameters).then(res => {
                if (res.code === 200) {
                    this.countList = res.data
                }
            })
        },
        //搜索
        search(val = {}) {
            this.queryParam = {
                ...val,
                // typeId: 4,

                fulfillBeginDate:
                    (val.finishedDate && val.finishedDate.length && val.finishedDate[0].format('YYYY-MM-DD')) || void 0,
                fulfillEndDate:
                    (val.finishedDate && val.finishedDate.length && val.finishedDate[1].format('YYYY-MM-DD')) || void 0,
                informantBeginDate:
                    (val.informantTime && val.informantTime.length && val.informantTime[0].format('YYYY-MM-DD')) || void 0,
                informantEndDate:
                    (val.informantTime && val.informantTime.length && val.informantTime[1].format('YYYY-MM-DD')) || void 0,
            }

            console.log("queryParam", this.queryParam)

            this.$refs.table.refresh(true)
        },
        handleFileUploaded(list) {
            this.form.files = [...list]
        },
        handleUpdate(type, data = {}) {
            this.visible = true;
            if (type == 'looks') {
                        this.disabled = true
                    } else {
                        this.disabled = false
                    }
            getDischargeOne({ id: data.id }).then((res) => {
                if (res.code == 200) {
                    const data = res.data
                    this.form = data
                    this.form.files = res.data.reviewFileInfoVOList

                }
            })
        },

        handleCancel(e) {
            //   console.log('Clicked cancel button');
            this.visible = false;
        },
        // 提交
        handleOk(e) {
            this.form.auditStatus = 'SUBMITTED'
            if (this.form.files <= 0) {
                this.$message.warning("请上传附件")
                return false
            }
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.confirmLoading = true;
                    this.form.informantDate = moment().format('YYYY-MM-DD')
                    saveDischargeList(this.form).then(res => {
                        this.confirmLoading = false;
                        if (res.code === 200) {
                            this.$message.success('成功')
                            this.visible = false;
                          
                            this.$refs.table.refresh(true)
                        } else {
                            this.$message.warning('失败')
                        }
                    })
                } else {
                    this.$message.warning("请填写完所有必填项信息")
                    return false
                }
            })
        },
    },
}
</script>
